﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Serialization;

namespace Tomahawk.Resources.Particles
{
    /// <summary>
    /// Settings class describes all the tweakable options used
    /// to control the appearance of a particle system.
    /// </summary>
    public sealed class ParticleSettings : ICloneable
    {
        // Name of this particle settings
        [XmlAttribute("Name")]
        public string name = "Undefined";

        // Name of the texture used by this particle system.
        [XmlElement("TextureName")]
        public string TextureName = null;


        // Maximum number of particles that can be displayed at one time.
        [XmlElement("MaxParticles")]
        public int MaxParticles = 100;


        // How long these particles will last.
        [XmlElement("Duration")]
        public float Duration = 1.0f;


        // If greater than zero, some particles will last a shorter time than others.
        [XmlElement("DurationRandomness")]
        public float DurationRandomness = 0;


        // Controls how much particles are influenced by the velocity of the object
        // which created them. You can see this in action with the explosion effect,
        // where the flames continue to move in the same direction as the source
        // projectile. The projectile trail particles, on the other hand, set this
        // value very low so they are less affected by the velocity of the projectile.
        [XmlElement("EmitterVelocitySensitivity")]
        public float EmitterVelocitySensitivity = 1;


        // Direction and strength of the gravity effect. Note that this can point in any
        // direction, not just down! The fire effect points it upward to make the flames
        // rise, and the smoke plume points it sideways to simulate wind.
        [XmlElement("Gravity")]
        public Vector3 Gravity = Vector3.Zero;


        // Controls how the particle velocity will change over their lifetime. If set
        // to 1, particles will keep going at the same speed as when they were created.
        // If set to 0, particles will come to a complete stop right before they die.
        // Values greater than 1 make the particles speed up over time.
        [XmlElement("EndVelocity")]
        public float EndVelocity = 1;


        // Range of values controlling the particle color and alpha. Values for
        // individual particles are randomly chosen from somewhere between these limits.
        [XmlElement("MinColor")]
        public Color MinColor = Color.White;

        [XmlElement("MaxColor")]
        public Color MaxColor = Color.White;


        // Range of values controlling how fast the particles rotate. Values for
        // individual particles are randomly chosen from somewhere between these
        // limits. If both these values are set to 0, the particle system will
        // automatically switch to an alternative shader technique that does not
        // support rotation, and thus requires significantly less GPU power. This
        // means if you don't need the rotation effect, you may get a performance
        // boost from leaving these values at 0.
        [XmlElement("MinRotateSpeed")]
        public float MinRotateSpeed = 0;

        [XmlElement("MaxRotateSpeed")]
        public float MaxRotateSpeed = 0;


        // Range of values controlling how big the particles are when first created.
        // Values for individual particles are randomly chosen from somewhere between
        // these limits.
        [XmlElement("MinStartSize")]
        public float MinStartSize = 100;

        [XmlElement("MaxStartSize")]
        public float MaxStartSize = 100;


        // Range of values controlling how big particles become at the end of their
        // life. Values for individual particles are randomly chosen from somewhere
        // between these limits.
        [XmlElement("MinEndSize")]
        public float MinEndSize = 100;

        [XmlElement("MaxEndSize")]
        public float MaxEndSize = 100;

        [XmlElement("Technique")]
        public string Technique = "Fire";

        #region ICloneable Members

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        #endregion
    }
}
